package cn.glinks.liuhe.app;


import cn.glinks.liuhe.BuildConfig;
import cn.glinks.liuhe.R;
import cn.glinks.liuhe.activity.MainActivity;
import cn.glinks.liuhe.api.jsonbean.ParksInfo;
import cn.glinks.liuhe.api.jsonbean.PersonalDetailsInfo;
import cn.glinks.liuhe.api.jsonbean.TestResult;
import cn.glinks.liuhe.api.jsonbean.UserInfo;
import cn.glinks.liuhe.base.BaseApplication;
import cn.glinks.liuhe.model.Interest;
import cn.glinks.liuhe.utils.LogUtils;
import cn.glinks.liuhe.utils.SPUtils;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import java.util.ArrayList;
import java.util.List;

/**
 * Des:AppApplication
 *
 * @author MarsBlade of Cyh
 * @created 2017-03-21 9:55
 */
public class AppApplication extends BaseApplication {

    // app的最近一次的前后台状态
    public int appLastStatus = 0;// 0->前台, 1->后台

    // 当前登录用户信息
    private boolean isUserLogin = false;
    private UserInfo loginUser = new UserInfo();

    // 统计数据缓存信息
    private ParksInfo statisticData = null;

    // 当前测评结果缓存信息
    private TestResult testResult = null;

    // 当前搜索的个人详细信息缓存信息
    private PersonalDetailsInfo personalDetailsInfo = null;

    // 试题缓存信息
    private String questions = null;

    // 爱好标签缓存列表
    private List<Interest> HobbyList = new ArrayList<>();
    private List<Interest> SportList = new ArrayList<>();
    private List<Interest> TravelList = new ArrayList<>();
    private List<Interest> IntercourseList = new ArrayList<>();
    private List<Interest> LivingList = new ArrayList<>();
    private List<Interest> CharacterList = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
        // 初始化腾讯Bugly
        Beta.autoInit = true;// app启动自动初始化升级模块
        Beta.autoCheckUpgrade = false;// 初始化时自动检查升级
        Beta.enableNotification = true;// 在通知栏显示下载进度
        Beta.autoDownloadOnWifi = false;// 在Wifi网络下不自动下载
        Beta.enableHotfix = false;// 禁用热更新功能
        Beta.canShowApkInfo = true;// 弹窗显示apk信息
        Beta.canShowUpgradeActs.add(MainActivity.class);// 添加可显示弹窗的Activity
        Bugly.init(getApplicationContext(), getResources().getString(R.string.bugly_app_id), true);
        // 初始化logger
        LogUtils.logInit(BuildConfig.LOG_DEBUG);
        // 初始化爱好标签缓存列表
        initInterestData(AppConstant.INTEREST_TAG_HOBBY, HobbyList);
        initInterestData(AppConstant.INTEREST_TAG_SPORT, SportList);
        initInterestData(AppConstant.INTEREST_TAG_TRAVEL, TravelList);
        initInterestData(AppConstant.INTEREST_TAG_INTERCOURSE, IntercourseList);
        initInterestData(AppConstant.INTEREST_TAG_LIVING, LivingList);
        initInterestData(AppConstant.INTEREST_TAG_CHARACTER, CharacterList);
    }

    /**
     * Des:初始化爱好标签缓存列表
     * @param tags 二级标签数组
     * @param list 二级标签缓存列表
     */
    private void initInterestData(String[] tags, List<Interest> list) {
        int i;
        list.clear();
        for (i = 0; i < tags.length; i++) {
            Interest interest = new Interest();
            interest.index = i;
            interest.label = tags[i];
            interest.isChecked = false;
            list.add(interest);
        }
    }

    /* APP前后台状态 */
    public int getAppLastStatus() {
        return appLastStatus;
    }

    public void setAppLastStatus(int appLastStatus) {
        this.appLastStatus = appLastStatus;
    }

    /* 当前登录用户信息接口 */
    public boolean getIsUserLogin() {
        return isUserLogin;
    }

    public void setIsUserLogin(boolean isUserLogin) {
        this.isUserLogin = isUserLogin;
    }

    public UserInfo getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(UserInfo loginUser) {
        this.loginUser = loginUser;
    }

    /* 统计数据缓存接口 */
    public ParksInfo getStatisticData() {
        return statisticData;
    }

    public void setStatisticData(ParksInfo statisticData) {
        this.statisticData = statisticData;
    }

    /* 测评结果缓存接口 */
    public TestResult getTestResult() {
        return testResult;
    }

    public void setTestResult(TestResult testResult) {
        this.testResult = testResult;
    }

    /* 当前搜索的个人详细信息缓存接口 */
    public PersonalDetailsInfo getPersonalDetailsInfo() {
        return personalDetailsInfo;
    }

    public void setPersonalDetailsInfo(PersonalDetailsInfo personalDetailsInfo) {
        this.personalDetailsInfo = personalDetailsInfo;
    }

    /* 试题缓存接口 */
    public String getQuestions() {
        return questions;
    }

    public void setQuestions(String questions) {
        this.questions = questions;
    }

    /* 爱好列表缓存接口 */
    public List<Interest> getHobbyList() {
        return HobbyList;
    }

    public List<Interest> getSportList() {
        return SportList;
    }

    public List<Interest> getTravelList() {
        return TravelList;
    }

    public List<Interest> getIntercourseList() {
        return IntercourseList;
    }

    public List<Interest> getLivingList() {
        return LivingList;
    }

    public List<Interest> getCharacterList() {
        return CharacterList;
    }

//    public void clearInterestList() {
//        ReadingList.clear();
//        BrowseList.clear();
//        EntertainmentList.clear();
//        DietList.clear();
//        TravelList.clear();
//        MusicList.clear();
//        FilmList.clear();
//        IntercourseList.clear();
//        ClothesList.clear();
//        LivingList.clear();
//        TrafficList.clear();
//        OtherList.clear();
//        CharacterList.clear();
//        SPUtils.setSharedBooleanData(this, AppConstant.IS_INTEREST_CHANGED, true);
//    }

    public void resetInterestList() {
        int i = 0;
        for(i = 0; i < HobbyList.size(); i++) {
            HobbyList.get(i).isChecked = false;
        }
        for(i = 0; i < SportList.size(); i++) {
            SportList.get(i).isChecked = false;
        }
        for(i = 0; i < TravelList.size(); i++) {
            TravelList.get(i).isChecked = false;
        }
        for(i = 0; i < IntercourseList.size(); i++) {
            IntercourseList.get(i).isChecked = false;
        }
        for(i = 0; i < LivingList.size(); i++) {
            LivingList.get(i).isChecked = false;
        }
        for(i = 0; i < CharacterList.size(); i++) {
            CharacterList.get(i).isChecked = false;
        }
        SPUtils.setSharedBooleanData(this, AppConstant.IS_INTEREST_CHANGED, true);
    }

}
